package service

import (
	"car/domain/model"
	"car/domain/repository"
)

type ICarDataService interface {
	AddCar(*model.Car) (int64 , error)
	DeleteCar(int64) error
	UpdateCar(*model.Car) error
	FindCarByID(int64) (*model.Car, error)
	FindAllCar() ([]model.Car, error)
}


//创建
func NewCarDataService(carRepository repository.ICarRepository) ICarDataService{
	return &CarDataService{ carRepository }
}

type CarDataService struct {
	CarRepository repository.ICarRepository
}


//插入
func (u *CarDataService) AddCar(car *model.Car) (int64 ,error) {
	 return u.CarRepository.CreateCar(car)
}

//删除
func (u *CarDataService) DeleteCar(carID int64) error {
	return u.CarRepository.DeleteCarByID(carID)
}

//更新
func (u *CarDataService) UpdateCar(car *model.Car) error {
	return u.CarRepository.UpdateCar(car)
}

//查找
func (u *CarDataService) FindCarByID(carID int64) (*model.Car, error) {
	return u.CarRepository.FindCarByID(carID)
}

//查找
func (u *CarDataService) FindAllCar() ([]model.Car, error) {
	return u.CarRepository.FindAll()
}

